#!/usr/bin/env python

def gotoxy(x, y, string):
#  H 绝对定位

    print("\033[%d;%dH%s" % (x, y, string), end='', flush=True)


def move(m):
#  ABCD   相对定位
#  A上  B下  C右  D左

    if m == 'up' and 'w':
        print("\033[1A@", end='', flush=True)
    if m == 'down' and 's':
        print("\033[1B@", end='', flush=True)
    if m == 'left' and 'a':
        print("\033[1D@", end='', flush=True)
    if m == 'right' and 'd':
        print("\033[1C@", end='', flush=True)


def selColor(c):
#       m 颜色
#   30 - 37 前景颜色
#   40 - 47 背景颜色
#   1 加粗

    print("\033[%cm" % c, end='', flush=True)


def cursor(string):
# ?25l 隐藏光标   ?25h 显示光标
# s 保存光标位置   u 还原光标位置
    str1 = ""
    if string == 'hide' or string == 0:
        str1 = '?25l'
    elif string == 'display' or string == 1:
        str1 = '?25h'
    print("\033[%s" % str1, end='', flush=True)


def screen(string):
# 2J 清屏    2K 清行

    str1 = ''
    if string == 'clear' or string == 0 or string == '2J' or string == '2j':
        str1 = '2J'
        gotoxy(1, 1, '')
    elif (string == 'clearone' or string ==0
            or string == '2K' or string == '2k'):
        str1 = '2K'

    print("\033[%s" % str1, end='', flush=True)





